package com.gt;

import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil;
import com.gt.data.GlobalData;
import com.gt.handler.QQMessageHandler;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.BotFactory;
import net.mamoe.mirai.event.events.MessageEvent;
import net.mamoe.mirai.utils.BotConfiguration;

public class ServerStartMain {

    public static void main(String[] args) {

        long qq = Long.parseLong(GlobalData.getValue("qq_number"));
        String pass = GlobalData.getValue("qq_password");
        final Bot bot = BotFactory.INSTANCE.newBot(qq, pass, new BotConfiguration() {
            {
                fileBasedDeviceInfo();
                setProtocol(MiraiProtocol.ANDROID_PAD); // 切换协议
            }
        });
        bot.login();

        //输出好友
        bot.getFriends().forEach(friend -> System.out.println(friend.getId() + ":" + friend.getNick()));
        bot.getEventChannel().subscribeAlways(MessageEvent.class, (event) -> {
            Console.log(StrUtil.format("收到消息-->{},type={}",event,event.getClass().getSimpleName()));
            QQMessageHandler.handle(event);
        });
    }



}
